what is wrong here <cfloop list="#getSettings.t...
# cfml-general
g
what is wrong here <cfloop list="#getSettings.timings#" index="data" delimiters="<br>"> <cfoutput>#data#</cfoutput> </cfloop> i am getting data as:
Copy code
Wed 6:00 PM - 6:45 PM F i 6:00 PM - 6:45 PM Sat 10:15 AM - 11:15 AM Sun 4:00 PM - 4:45 PM Sun 5:00 PM - 5:45 PM Wed 7:00 PM - 7:45 PM F i 7:00 PM - 7:45 PM Sat 11:15 AM - 12:15 PM
please note here, the
r
is missing is
fri
and other issues data is database is stored:
Copy code
Wed 6:00 PM - 6:45 PM <br> Fri 6:00 PM - 6:45 PM <br> Sat 10:15 AM - 11:15 AM <br> Sun 4:00 PM - 4:45 PM <br> Sun 5:00 PM - 5:45 PM <br> Wed 7:00 PM - 7:45 PM <br> Fri 7:00 PM - 7:45 PM <br> Sat 11:15 AM - 12:15 PM <br>
d
r is listed as one of the delimiters, in your example. It checks for any of the characters as delimiters, not the combination of them. https://trycf.com/gist/e8c36dc9d287c244961a9981452aa5e1/lucee5?theme=monokai
g
in this case, its coming from DB, so you are suggesting i can change delmiter before i run the loop or how?
m
You can assign that list to another variable first and replace the br to another delimiter. For example, <cfset local.updatedList = ReplaceNoCase(getSettings.timings, "br", "|", "all")> " cfoutput#data#/cfoutput /cfloop
Or you can use pipe (or any other character of your choice) as the delimiter and save it in the database that way. When you display on the screen, that's when you replace the pipes with <br>'s. Not sure which way is easier for you though.
a
OK I think you misread / misunderstood the docs: https://helpx.adobe.com/uk/coldfusion/cfml-reference/coldfusion-tags/tags-j-l/cfloop-looping-over-a-list-a-file-or-an-array.html#cfloopList
Delimiters Optional Characters that separate list items.
My emphasis. They're character delimiters, not a string delimiter. It's always important to read the docs when... using functionality. Second: I reckon you probably could have worked this out for yourself if you spent even a small amount of time reasoning through what you were seeing. Third: I'd not loop over a list here (I'd never use a list as a collection type). I'd convert the string to an array, especially as
listToArray
handles multi-char delimiters. https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-l/listtoarray.html https://trycf.com/gist/14280373e3fc29f2ee4f522e6f534f1c/acf2023?theme=monokai The important one here is the second point: debug yer code. Which would involve the first point: read the docs.